﻿using Autofac;
using DevExpress.Mvvm.UI;
using System.Windows;
using WpfApp1.Themes;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private readonly DIContainerBuilder _mainBuilder = new();
        public static ILifetimeScope LifetimeScope { get; private set; }

        protected override void OnStartup(StartupEventArgs e)
        {
            //PaletteHelper.ChangeTheme(PaletteHelper.ThemeType);

            var dependencyContainer = _mainBuilder.GetBuiltContainer();
            LifetimeScope = dependencyContainer.BeginLifetimeScope();
            var exceptionHandler = LifetimeScope.Resolve<ExceptionHandler>();
            exceptionHandler.SetupExceptionHandlingEvents(this);

            var mainWindow = ViewLocator.Default.ResolveView(nameof(MainWindow)) as Window; 
            mainWindow.Show();  
        }

        protected override void OnExit(ExitEventArgs e)
        {
            LifetimeScope.Dispose();
            base.OnExit(e);
        }
    }

}
